<?php
		require_once(dirname(__FILE__) . "/start.inc");
		global $CONFIG;

	$scheme = $_GET['scheme'];
	$host = $_GET['host'];

	if ($scheme && $host) {
		$url = $scheme.'://'.$host;

		// TODO: We should check the validation of the url
		// $result = filter_var($url, FILTER_VALIDATE_URL);

		if (endsWith($url, '.js') || endsWith($url, '.css') || endsWith($url, '.jpg') || endsWith($url, '.gif') || endsWith($url, '.png')) {
			$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
			//error_log('[edit.php]2---------->'.$CONFIG->getEditUrlHost($referer));
			if (startsWith($host, '/')) {
					$url = $CONFIG->getEditUrlHost($referer).$host;
			} else {
					$url = $CONFIG->getEditUrlHost($referer).'/'.$host;
			}
			error_log('redirect: '.$url);
			header('Location:'.$url);
			exit();
		} else {
			$result = getUrl($url);
			echo $result['content'];

			echo get_include_contents("views/elements.php");
			echo get_include_contents("views/html_includes.php", array('isEditPage' => true));
			if (getVar('vId')) {
		?>
			<script type='text/javascript' src='<?php echo $CONFIG->getLocalhostUrl();?>/code?vId=<?php echo getVar('vId');?>'></script>
		<?php
			}
		}
	} else {
		die('Can not load the page: '.$scheme.'://'.$host);
	}
?>